import copy

def recognizer(code):
    outList = []
    state = ('1', '2', '3')  # 有3个状态
    state = 1  # 初始状态为1
    i = 0
    id = ''  # 标识符
    while i<len(code):
        char = code[i]
        match state:
            case 1:
                if ('A' <= char <= 'Z') or ('a' <= char <= 'z') or (char == '_'):
                    id += char
                    state = 2
                pass
            case 2:
                if ('A' <= char <= 'Z') or ('a' <= char <= 'z') or ('0' <= char <= '9') or (char == '_'):
                    id += char  
                    state = 2
                else:
                    state = 3
                    outList.append(copy.deepcopy(id))
                pass
            case 3:
                id = ''
                state = 1 #识别结束、回到初始状态
                i-=1
                pass
        i += 1
    return outList

if __name__ == '__main__':
    code = "int var1; float var2;"
    print(code)

    ids = recognizer(code)
    print(ids)
